using System;
using System.Threading;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace Dashboard.Engine.Backends
{
	public class ScreenScraperBackend : IComponent
	{
		public string Name
		{
			get { return "Screen Scraper Backend"; }
		}

		public string Description 
		{
			get { return "Scrapes the screen automatically for clues by looking at windows \"visually\""; }
		}

		public void Initialize ()
		{
			try {
				SPI_init ();
			} catch (DllNotFoundException ex) {
				Engine.Logger.Warn (this, "Accessability libraries not found, cannot initialize");
				return;
			}

			Thread thread = new Thread (new ThreadStart (ScraperWorker));
			thread.Start ();
		}

		public void Dispose ()
		{
			SPI_exit ();
		}
		
		private void ScraperWorker ()
		{

		}

		[DllImport ("libcspi")]
		private static extern void SPI_init ();

		[DllImport ("libcspi")]
		private static extern void SPI_event_main ();

		[DllImport ("libcspi")]
		private static extern void SPI_exit ();

		[DllImport ("libcspi")]
		private static extern void SPI_freeString (IntPtr s);

		[DllImport ("libcspi")]
		private static extern void SPI_unref (IntPtr o);

		[DllImport ("libcspi")]
		private static extern int SPI_getDesktopCount ();

		[DllImport ("libcspi")]
		private static extern IntPtr SPI_getDesktop (int i);

		[DllImport ("libcspi")]
		private static extern IntPtr Accessible_getName (IntPtr accessible);

		[DllImport ("libcspi")]
		private static extern IntPtr Accessible_getRoleName (IntPtr accessible);

		[DllImport ("libcspi")]
		private static extern int Accessible_getChildCount (IntPtr accessible);

		[DllImport ("libcspi")]
		private static extern IntPtr Accessible_getChildAtIndex (IntPtr accessible, int i);
	}
}